package com.stylefeng.guns.modular.system.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.stylefeng.guns.common.constant.Const;
import com.stylefeng.guns.common.persistence.model.Region;
import com.stylefeng.guns.common.persistence.dao.RegionMapper;
import com.stylefeng.guns.common.persistence.model.User;
import com.stylefeng.guns.core.base.tips.ErrorTip;
import com.stylefeng.guns.modular.system.service.IRegionService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wys123
 * @since 2018-01-25
 */
@Service
public class RegionServiceImpl extends ServiceImpl<RegionMapper, Region> implements IRegionService {

    @Autowired
    RegionMapper regionMapper;
    @Override
    public List<Region> selectListByPid(String s) {
        Wrapper<Region> wrapper = new EntityWrapper<>();
        wrapper = wrapper.where("parent_id={0}", s);
        List<Region> list=this.selectList(wrapper);
        return list;
    }

    @Override
    public Region selectByNameAndPid(String ret15, int i) {
//        List<Region> list=regionMapper.selectReglionList(ret15,i);
//        return list.get(0);
        Wrapper<Region> wrapper = new EntityWrapper<>();
        wrapper = wrapper.where("parent_id="+ i).andNew(" region_name LIKE CONCAT('%"+ret15+"%')");
        List<Region> list=this.selectList(wrapper);
        return list.get(0);


    }

    @Override
    public Map<String, String> selectReglionId(String ret15) {
        return regionMapper.selectReglionId(ret15);
    }
}
